<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm" label-width="110px" label-position="right">
            <el-row :gutter="1">
                <el-col :span="12">
                    <el-form-item label="项目编号" prop="project_id">
                        <el-input v-model="project_code" readonly placeholder="请选择项目" @click="checkItem"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="会议名称" prop="metting">
                        <el-input v-model="metting" readonly placeholder="请选择项目"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="1">
                <el-col :span="12">
                    <el-form-item label="宴会厅名称" prop="banquet_name">
                        <el-input v-model="banquet_name" readonly placeholder="宴会厅名称"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="会议日期" prop="project_time">
                        <el-input v-model="project_time" readonly placeholder="会议日期"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="1">
                <el-col :span="12">
                    <el-form-item label="预售金额" prop="pre_sale">
                        <el-input v-model="form.pre_sale" placeholder="预售金额" :readonly="mode != 'add'"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="预售状态" prop="pre_status">
                        <el-select v-model="form.pre_status" placeholder="请选择预售状态" clearable>
                            <el-option label="预售中" :value="0"/>
                            <el-option label="已退款" :value="1"/>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-col :span="12">
                <el-form-item label="拍照上传" prop="photo_files">
                    <sc-upload-multiple width='50' height='50' v-model="form.photo_files" draggable :disabled="mode != 'add'"></sc-upload-multiple>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="创建时间" prop="date">
                    <el-date-picker v-model="date" type="date" placeholder="请选择创建时间" style="width: 100%;" :value-format="'YYYY-MM-DD'" disabled></el-date-picker>
                </el-form-item>
            </el-col>
		</el-form>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新增',
				edit: '编辑',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			//表单数据
			form: {
                id:"",
                project_id:"",
                pre_sale:"",
                photo_files:"",
                pre_status:"",
			},
            date:this.moment().format('YYYY-MM-DD'),
            project_code: "",
            metting: "",
            banquet_name: "",
            project_time: "",
			//验证规则
			rules: {
				enterprise: [{ required: true, message: '请输入名称' }],
			},
            dialog:{
                item:false,
            },
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = [];
					if (this.form.id) {
						res = await this.$API.project.hotel.edit.post(this.form);
					} else {
						res = await this.$API.project.hotel.add.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 1) {
						this.$emit('success', this.form, this.mode)
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", { type: 'error' })
					}
				} else {
					return false;
				}
			})
		},
        projectData(data){
            this.form.project_id = data.project_id
            this.project_code = data.project_code
            this.metting = data.project_name
            this.banquet_name = data.banquet_name
            this.project_time = data.project_time
        },
		//表单注入数据
		setData(data) {
			//可以和上面一样单个注入，也可以像下面一样直接合并进去
            this.form.id = data.id
            this.form.project_id = data.project_id
            this.form.pre_sale = data.pre_sale
            this.form.pre_status = data.pre_status
            this.form.photo_files = data.photo_files
            this.date = data.create_time
            this.project_code = data.project.project_code
            this.metting = data.project.metting
            this.banquet_name = data.project.banquet.banquet_name
            this.project_time = data.project.project_time
		},
        checkItem(){
            if(this.mode == 'add'){
                this.dialog.item = true
                this.$nextTick(() => {
                    this.$refs.itemDialog.open('add')
                })
            }
        },
        itemBack(data){
            this.form.project_id = data.id
            this.project_code = data.project_code
            this.metting = data.metting
            this.project_time = data.project_time
            this.banquet_name = data.banquet.banquet_name
        },
	}
}
</script>

<style></style>
